﻿using System;
using Autodesk.Revit.UI;
using YJKRevitBase.WinForm;
using YJKWndrStatisticsExcel.FastStatisticTable.CommonForms;
using System.Windows.Forms;

namespace YJKWndrStatisticsExcel.FastStatisticTable.Utility
{
	public class FastMaterialDlgApp : IExternalApplication
	{
		public Result OnShutdown(UIControlledApplication application)
		{
			if (FastMaterialDlgApp.m_MyForm != null && FastMaterialDlgApp.m_MyForm.Visible)
			{
				FastMaterialDlgApp.m_MyForm.Close();
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public Result OnStartup(UIControlledApplication application)
		{
			FastMaterialDlgApp.m_MyForm = null;
			FastMaterialDlgApp.thisApp = this;
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public void ShowForm(ExternalCommandData commandData, WindowHandle _hWndRevit, bool bDoorWind = false)
		{
			if (FastMaterialDlgApp.m_MyForm == null || FastMaterialDlgApp.m_MyForm.IsDisposed)
			{
				FastMaterialRequestHandler fastMaterialRequestHandler = new FastMaterialRequestHandler();
				ExternalEvent exEvent = ExternalEvent.Create(fastMaterialRequestHandler);
				FastMaterialDlgApp.m_MyForm = new DlgFastMaterialStatistic(commandData, _hWndRevit, fastMaterialRequestHandler, exEvent, bDoorWind);
			}
			if (!FastMaterialDlgApp.m_MyForm.Created)
			{
				FastMaterialDlgApp.m_MyForm.Show(_hWndRevit);
			}
		}

		public static FastMaterialDlgApp thisApp;

		public static DlgFastMaterialStatistic m_MyForm;
	}
}
